import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:nft_shop/my/model/models.dart';
import 'package:nft_shop/net/service_repository.dart';
import 'package:nft_shop/res/constant.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import '../model/models.dart';

class SiftConteroller extends GetxController {
  static final bannersID = "bannersID";
  static final topArticlesID = "topArticlesID";
  static final siftPageID = "siftPageID";

  late List<Article> banners = [];
  late List<Article> topArticles = [];

  int currentPage = 0;

  VoidCallback?   refreshBlock;

  static SiftConteroller get to => Get.find<SiftConteroller>();

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

  }

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
    getDataList();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
  }

  //获取数据
  void getDataList() async {
    print("数据请求------");
    getBanners();
    // getArticle();
    if(refreshBlock != null){
      refreshBlock!();
    }
  }

  //轮播图
  void getBanners() async{
    try{
      banners = await ServiceRepository.fetchBanners(type: 3,);
      update([bannersID]);
    }catch (e, s) {

    }
  }

  //公告
  void getArticle() async{
    try{
      topArticles = await ServiceRepository.fetchBanners(type: 2,);
      print("---触发公告刷新");
      update([topArticlesID]);
    }catch (e, s) {

    }
  }

}
